<?php
  //Buffer larger content areas like the main page content
  ob_start();
  require_once("auth.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" src="js/validationorddetail.js"></script>
<script>
var count=0;

function load(thediv, thefile) /* 2 parameters passed into here: the id of the div container and the name of the page to go to */
{  
    if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    }
    else
    {
        xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');  
    }
    xmlhttp.addEventListener("error", transferFailed, false);  
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            document.getElementById( thediv ).innerHTML = xmlhttp.responseText;
        }
    }  
 
   xmlhttp.open('GET', thefile, true);
    xmlhttp.send();
	    
}

function transferFailed(evt) {  
  alert("An error occurred while transferring the file.");  
}

</script>
</head>
<body>
<?php 
include("config.php");
if(isset($_REQUEST['id']))
{
$id=$_REQUEST['id'];
$data=mysql_query("select * from orderdetails where OrderDetailID='$id'");
$no=mysql_num_rows($data);
if($no!=0)
{
	while($rec=mysql_fetch_assoc($data))
	{

?>

<form action="updateorderdetails.php" method="post"  enctype="multipart/form-data" id="frmorderdetails">
<fieldset >
<legend style="color:#FD0002">Update Order Details </legend>
			<div id="status"></div>

<table width="80%" align="center">
<tr >
<td  >Product Id: </td>
<td  ><input type="hidden" name="id" value="<?php echo $id; ?>" />
  <select id="ddlProductId" name="ddlProductId">
    <?php 
							$data1=mysql_query("select * from products order by serial");

							$no1=mysql_num_rows($data1);
							if($no1!=0)
							{
								while($rec1=mysql_fetch_assoc($data1))
								{

							?>
    <option <?php if($rec['ProductID']==$rec1['serial']) echo 'selected="selected"'; ?> ><?php echo $rec1['serial']; ?> </option>
    <?php
							}
							}
							?>
  </select></td>
</tr>
<tr>
 <td >Order Id </td>
<td ><select id="ddlOrderId" name="ddlOrderId">
<?php 
							$data1=mysql_query("select * from orders");
							$no1=mysql_num_rows($data1);
							if($no1!=0)
							{
								while($rec1=mysql_fetch_assoc($data1))
								{

							?>
							<option  <?php if($rec['OrderID']==$rec1['OrderID']) echo 'selected="selected"'; ?>><?php echo $rec1['OrderID']; ?> </option>
							<?php
							}
							}
							?>


</select></td>
</tr>
<tr>
<td>Price:</td>
<td><input type="text" name="txtPrice" id="txtPrice"  value="<?php echo $rec['Price']; ?>"  onkeypress="return numbersonly(event);"></td>
</tr>
<tr>
<td>Quantity:</td>
<td><input type="text" name="txtQuantity" id="txtQuantity"  value="<?php echo $rec['Quantity']; ?>"  onkeypress="return numbersonly(event);"></td>
</tr>
<tr>
<td style="display:none"><input type="text" name="txtTotal" id="txtTotal"  value="<?php echo $rec['Total']; ?>"    ></td>
</tr>

<tr><td colspan="3"><input type="button" value="Update Orderdetails" name="btnUpdateOrderdetails" onclick="validateForm2('updateorderdetails.php','frmorderdetails','thediv','<img src=\'pleasewait.gif\'>');" /></td></tr>
</table>
</fieldset>
  	</form>
	
	
	<?php
	}
	}
	}
	else
	{
	?>
	
	
	<form action="addorderdetails.php" method="post"  enctype="multipart/form-data" id="frmorderdetails">
<fieldset >
<legend style="color:#FD0002">Add Order Details </legend>
			<div id="status"></div>

<table width="80%" align="center">
<tr>
<td >Product Id: </td>
<td ><select id="ddlProductId" name="ddlProductId">

<?php 
						$data1=mysql_query("select * from products order by serial");

							$no1=mysql_num_rows($data1);
							if($no1!=0)
							{
								while($rec1=mysql_fetch_assoc($data1))
								{

							?>
							<option ><?php echo $rec1['serial']; ?> </option>
							<?php
							}
							}
							?>

</select></td>
</tr>
<tr>
 <td >Order Id </td>
<td ><select id="ddlOrderId" name="ddlOrderId">
<?php 
							$data1=mysql_query("select * from orders");
							$no1=mysql_num_rows($data1);
							if($no1!=0)
							{
								while($rec1=mysql_fetch_assoc($data1))
								{

							?>
							<option><?php echo $rec1['OrderID']; ?> </option>
							<?php
							}
							}
							?>


</select></td>

</tr>

<td>Price:</td>
<td><input type="text" name="txtPrice" id="txtPrice"  onkeypress="return numbersonly(event);"></td>

</tr>
<tr>
<td>Quantity:</td>
<td><input type="text" name="txtQuantity" id="txtQuantity"  onkeypress="return numbersonly(event);"></td>
</tr>
<tr>
<td style="display:none"><input type="text" name="txtTotal" id="txtTotal"  onkeypress="return numbersonly(event);"></td>
</tr>
<tr><td colspan="3"><input type="button" value="Add Orderdetails" name="btnAddOrderdetails"  onclick="validateForm2('addorderdetails.php','frmorderdetails','thediv','<img src=\'pleasewait.gif\'>');"/></td></tr>

</table>
</fieldset>
  	</form>
<?php
}
?>
</body>
</html>
 <?php
  //Assign all Page Specific variables
  $pagemaincontent = ob_get_contents();
  ob_end_clean();
  $pagetitle = "Order details";
  //Apply the template
  include("master.php");
?>    